﻿#include "Bytes2Int.h"
#include <stdint.h>
#include <cstddef>

// ====================== 字节序转 Int ======================

// 大端字节序 → int
uint32_t BytesToIntBe(const uint8_t *bytes, int len)
{
    if (bytes == NULL || len < 4) {
        return 0; // 或者返回错误码
    }

    return ((uint32_t)bytes[0] << 24) |
           ((uint32_t)bytes[1] << 16) |
           ((uint32_t)bytes[2] << 8)  |
           (uint32_t)bytes[3];
}

// 小端字节序 → int
uint32_t BytesToIntLe(const uint8_t *bytes, int len)
{
    if (bytes == NULL || len < 4) {
        return 0; // 或者返回错误码
    }
    return ((uint32_t)bytes[3] << 24) |
           ((uint32_t)bytes[2] << 16) |
           ((uint32_t)bytes[1] << 8)  |
           (uint32_t)bytes[0];
}
